package com.moon.admin.tools.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.moon.admin.tools.entity.GenTableColumn;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 业务字段 数据层
 * 
 * @author ninglong
 */
@Mapper
public interface GenTableColumnMapper extends BaseMapper<GenTableColumn> {
    @Select("<script>"+
            "select column_name as columnName, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as isRequired, (case when column_key = 'PRI' then '1' else '0' end) as isPk, column_comment as columnComment, (case when extra = 'auto_increment' then '1' else '0' end) as is_Increment, column_type as columnType" +
            " from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName}) " +
            " order by ordinal_position"+
            "</script>")
    /**
     * 根据表名称查询列信息
     *
     * @param tableName 表名称
     * @return 列信息
     */
    List<GenTableColumn> selectDbTableColumnsByName(String tableName);
}
